package com.sam.demo.spring.boot.jpa.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@EnableJpaRepositories(basePackages = "com.sam.demo.spring.boot.jpa.secondary", entityManagerFactoryRef = "secondaryEntityManagerFactory", transactionManagerRef = "transactionManager")
@Configuration
@ConfigurationProperties(prefix = "spring.datasource.secondary")
@EnableTransactionManagement(proxyTargetClass = true)
public class SecondaryJpaConfig extends JpaConfigCommon {

	@Bean(name = "secondaryDataSource")
	public DataSource dataSource() {
		return super.dataSource("secondary");
	}

	@Bean(name = "secondaryEntityManagerFactory")
	@DependsOn({ "atomikosJtaPlatfom" })
	public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
		return super.entityManagerFactory("secondary","com.sam.demo.spring.boot.jpa.secondary");
	}
}
